﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Common;

namespace Ym.print
{
    public partial class NewsEdit : PrintPageBase
    {
        private PBLL.PNews bll = new PBLL.PNews();
        public string id = "0";
        private int hit = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Random rand = new Random();
                hit = rand.Next(200);

                if (string.IsNullOrEmpty((string)Session["UserName"]))
                {

                }
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    id = Request.QueryString["id"].ToString();
                    PModel.PNews model = bll.GetModel(id);
                    txtTitle.Text = model.NTitle;
                    hit = model.NHit;
                    elm1.Value = model.NCont;
                    ne.InnerText = "修改印刷常识";
                }
                else
                {
                    ne.InnerText = "添加印刷常识";
                }
                txtHits.Text = hit.ToString();
                ihidden.Value = id;
            }
        }

        protected void save_Click(object sender, EventArgs e)
        {
            PModel.PNews model = new PModel.PNews();

            model.NTitle = txtTitle.Text;
            model.NCont = elm1.Value;
            model.NHit = int.Parse(txtHits.Text);
            if (ihidden.Value == "0")
            {
                model.NTime = DateTime.Now;
                bll.Insert(model);
                JscriptPrint("添加成功！", "News.aspx", "Success");
            }
            else
            {
                model.Id = int.Parse(ihidden.Value);
                bll.Update(model);
                JscriptPrint("修改成功！", "News.aspx", "Success");
            }
        }
    }
}